package com.cn.web.servlet;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cn.domain.Product;

public class DeleteCartServlet extends BaseServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String id = request.getParameter("id");
		Product product = ps.getProductById(Integer.parseInt(id));
		Map<Product,Integer> map = (Map<Product, Integer>) request.getSession().getAttribute("cart");
		if(map == null){
			response.sendRedirect(request.getContextPath()+"/cart.jsp");
			return;
		}
		map.remove(product);
		response.sendRedirect(request.getContextPath()+"/cart.jsp");
	}

}
